<?php

require_once("lib/exception/internal_error_exception.php");
require_once("lib/exception/instance_not_found_exception.php");

require_once("lib/model/action.php");
require_once("model/article_article_category/dao/article_article_category_dao_factory.php");
require_once("model/article_category/dao/article_category_dao_factory.php");
require_once("model/article_category/to/article_category_to.php");

class Find_categories_by_article_action implements Action {

	private $article_number;
	
	public function __construct($article_number) {
		
		$this->article_number = $article_number;
	}
	
	public function do_execute() {
		try {
			$dao = Article_article_category_dao_factory::singleton()->get_dao();
			$category_list = $dao->find_by_number_article($this->article_number);
			
			$dao = Article_category_dao_factory::singleton()->get_dao();
			$i = 0;
			foreach($category_list as $category) 
				$category_to_list[$i++] = $dao->find_by_number_article_category($category);
			
			return $category_to_list;
		}
		catch (Instance_not_found_exception $e) {
			throw new Model_exception($e);
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}
	}
	
}

?>